<template>
<div class="login-page">
  <el-form :model="user" label-width="70" ref="registerForm">
    <div class="form-label">
      <h1>注册表</h1>
    </div>
    <el-form-item label="账号">
      <el-input type="text" v-model="user.username"></el-input>
    </el-form-item>
    <el-form-item label="邮箱">
      <el-input type="text" v-model="user.email"></el-input>
    </el-form-item>
    <el-form-item label="昵称">
      <el-input v-model="user.nickname"></el-input>
    </el-form-item>
    <el-form-item label="密码">
      <el-input type="password" v-model="user.password" show-password></el-input>
    </el-form-item>
    <el-form-item label="确认密码">
      <el-input type="password" v-model="user.checkPassword" show-password></el-input>
    </el-form-item>
    <div class="register-button">
      <el-button type="primary" style="width: 100%" @click="toRegister">注册</el-button>
    </div>
  </el-form>
</div>
</template>

<script>
import { ref } from 'vue'
import { userRegister } from '@/api/user'
import router from '@/router'

export default {
  name: 'UserRegister',
  setup () {
    return {
      user: ref({
        nickname: '',
        username: '',
        password: '',
        email: ''
      })
      // rules:ref({
      //
      // })
    }
  },
  methods: {
    toRegister () {
      this.$refs.registerForm.validate((val) => {
        console.log(val)
        if (val) {
          userRegister(this.user).then((val) => {
            console.log(val)
            router.push('/login')
          })
        }
      })
    }
  }
}
</script>

<style scoped>
.register-button{
  margin-left: 50px;
  margin-right: 20px;
}
.login-page{
  width: 600px;
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 600px;
  background-color: #e3eeef;
}
.form-label{
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 30px 30px;
  padding-top: 0;
}
.login-addition{
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: space-between;
}
.el-form{
  width: 300px;
}
</style>
